package eclipse.server.data;
import eclipse.util.io.*;
/**
 * A Class that represents the Account file that is located on the server.
 */
public class Account
{
	private String uName;
	private String pWord;	
	public boolean loadAccount(int index, String sAccount, String sPassword)
	{
		sAccount = sAccount.toLowerCase();
		if(IOTools.fileExists("Accounts/" + sAccount))
			return false;
		PropertyFile pAccount = new PropertyFile("Accounts/" + sAccount + ".dat");
		
		if(!sPassword.equals(pAccount.readProperty("ACCOUNT", "PASSWORD")))
			return false;
		//TODO: login statements
		return true;		
	}
	/**
	 * Creates a new Account
	 * @param sAccount Account name as String
	 * @param sPassword Account password as String
	 */
	public boolean makeAccount(String sAccount, String sPassword)
	{
		sAccount = sAccount.toLowerCase();
		if(IOTools.fileExists("Accounts/" + sAccount + ".dat"))
			return false;
		
		IOTools.makeFile("Accounts/" + sAccount + ".dat");
		PropertyFile pAccount = new PropertyFile("Accounts/" + sAccount + ".dat");
		
		pAccount.writeProperty(sAccount, "ACCOUNT", "LOGIN");			
		pAccount.writeProperty(sPassword, "ACCOUNT", "PASSWORD");
		pAccount.writeProperty("0", "ACCOUNT", "ACCESS");		
		pAccount = null;
		uName = sAccount;
		pWord = sPassword;
		return true;
	}
	/** Returns the login for the Account */
	public String getLogin()
	{
		return uName;
	}
	/** Returns the password for the Account */
	public String getPassword()
	{
		return pWord;
	}
}
